package com.tulingxueyuan.mall.modules.oms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.common.api.CommonPage;
import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsOrderDeliveryParamDTO;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsOrderDetailDTO;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsOrderQueryParamDTO;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsReceiverInfoParamDTO;
import com.tulingxueyuan.mall.modules.oms.service.OmsOrderService;
import com.tulingxueyuan.mall.modules.oms.service.OmsOrderSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author zhaofuhao
 * @since 2022-03-03
 */

@RestController
@Api(tags = "OmsOrderController", description = "订单管理")
@RequestMapping("/order")
public class OmsOrderController {

    @Autowired
    private OmsOrderService orderService;
    /**
     *   return request({
     *     url:'/order/list',
     *     method:'get',
     *     params:params
     *   })
     */
    @ApiOperation("查询订单")
    @GetMapping("/list")
    @ResponseBody
    public CommonResult list(OmsOrderQueryParamDTO queryParam){
        Page page = orderService.list(queryParam);
        return CommonResult.success(CommonPage.restPage(page));
    }
    /**
     *   return request({
     *     url:'/order/'+id,
     *     method:'get'
     *   });
     */
    @ApiOperation("获取订单详情:订单信息、商品信息、操作记录")
    @GetMapping("/{id}")
    @ResponseBody
    public CommonResult detail(@PathVariable Long id) {
        OmsOrderDetailDTO orderDetailResult = orderService.detail(id);
        return CommonResult.success(orderDetailResult);
    }
    @ApiOperation("备注订单")
    @PostMapping("/update/note")
    @ResponseBody
    public CommonResult updateNote(@RequestParam("id") Long id,
                                   @RequestParam("note") String note,
                                   @RequestParam("status") Integer status){
      boolean count=orderService.updateNote(id,note,status);
      if (count){
          return  CommonResult.success(count);
      }
      return CommonResult.failed();

    }
    /**
     *  修改收货人信息
     *  return request({
     *     url:'/order/update/receiverInfo',
     *     method:'post',
     *     data:data
     *   });
     */
    @PostMapping("/update/receiverInfo")
    @ResponseBody
    public CommonResult updateReceiverInfo(@RequestBody OmsReceiverInfoParamDTO receiverInfoParam){
        boolean count = orderService.updateReceiverInfo(receiverInfoParam);
        if (count) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("批量关闭订单")
    @PostMapping("/update/close")
    @ResponseBody
    public CommonResult close(@RequestParam("ids")List<Long> ids,@RequestParam String note){
        boolean count = orderService.close(ids,note);
        if (count) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("批量发货")
    @PostMapping("/update/delivery")
    @ResponseBody
    public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParamDTO> deliveryParamList) {
        boolean count = orderService.delivery(deliveryParamList);
        if (count) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("批量删除订单")
    @PostMapping("/delete")
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
        Boolean count = orderService.delete(ids);
        if (count) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }




}

